package com.wicket.okrbff.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.wicket.okrbff.biz.service.CommonService;
import com.wicket.okrbff.biz.service.dto.common.BffObjAttributeIdDto;
import com.wicket.okrbff.biz.service.dto.req.GetSpaceInfoFromRedisReqDto;
import com.wicket.okrbff.biz.service.dto.req.*;
import com.wicket.okrbff.biz.service.dto.res.GetSpaceInfoFromRedisRespDto;
import com.wicket.okrbff.biz.service.dto.res.*;
import com.wicket.okrbff.biz.service.nb.NbCommon;
import com.wicket.okrbff.common.annotations.BanAuto;
import com.wicket.okrbff.common.baseinfo.BaseInfoDO;
import com.wicket.okrbff.common.dto.TreeNode;
import com.wicket.okrbff.common.enums.ImageEnums;
import com.wicket.okrbff.common.exception.BizException;
import com.wicket.okrbff.common.util.CommonFunctionHelper;
import com.wicket.okrbff.common.util.RandomUtils;
import com.wicket.okrbff.common.util.RedisUtil;
import com.wicket.okrframework.integration.FwBaseCommonClient;
import com.wicket.okrframework.integration.FwBaseDivineDataClient;
import com.wicket.okrframework.integration.dto.*;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.lang3.StringUtils;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.wicket.okrbff.common.exception.Assert;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class CommonServiceImpl implements CommonService {
    private static final String SPACE = "SPACE";
    /**
     * 平台
     */
    private static final String PLATFORM = "PLATFORM";
    /**
     * 默认空间
     */
    private static final String DEFAULT = "DEFAULT";
    @Resource
    FwBaseCommonClient commonClient;
    @Resource
    FwBaseDivineDataClient divineDataClient;
    @Resource
    NbCommon nbCommon;
    @Resource
    FwBaseCommonClient fwBaseCommonClient;
    @Resource
    FwBaseDivineDataClient fwBaseDivineDataClient;
    @Resource
    private RedisUtil redisUtil;

    /**
   * B查询前端公共信息列表（公共）[1404]
   * gen by moon at 9/2/2022, 3:00:09 PM
   */
    @Trace(operationName = "B查询前端公共信息列表（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryFrontPublicInfoListRespDto queryFrontPublicInfoList(BffQueryFrontPublicInfoListReqDto reqDto){
      
       
       QueryFrontPublicInfoListRespDto queryFrontPublicInfoListRespDto_1 =null;
//步骤0: D1查询空间框架信息前端缓存 - queryFrontPublicInfoList
     QueryFrontPublicInfoListRespDto queryFrontPublicInfoListRespDto = null;
    QueryFrontPublicInfoListReqDto queryFrontPublicInfoListReqDto=new QueryFrontPublicInfoListReqDto();
  
  
    /*D1查询空间框架信息前端缓存[1405]   */
    
      queryFrontPublicInfoListRespDto = fwBaseCommonClient.queryFrontPublicInfoList(queryFrontPublicInfoListReqDto).getData();
      
      
      queryFrontPublicInfoListRespDto_1 = queryFrontPublicInfoListRespDto;
    
BffQueryFrontPublicInfoListRespDto retData = new BffQueryFrontPublicInfoListRespDto();
  if(queryFrontPublicInfoListRespDto_1!=null){
      retData.setTypeEncodingList(queryFrontPublicInfoListRespDto_1.getTypeEncodingList().stream().map(item -> BeanUtil.toBean(item, BffTypeEncodingDto.class)).collect(Collectors.toList()));//sourceId:32447_1
retData.setBaseMetadataObjectPropertyList(queryFrontPublicInfoListRespDto_1.getBaseMetadataObjectPropertyList().stream().map(item -> BeanUtil.toBean(item, BffBaseMetadataObjectPropertyDto.class)).collect(Collectors.toList()));//sourceId:32448_1
    }
  

  
  
return retData;
  }

    /**
   * B查询空间框架信息前端缓存（公共）[1045]
   * gen by moon at 8/10/2022, 3:31:55 AM
   */
    @Trace(operationName = "B查询空间框架信息前端缓存（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryFrameInfoFrontCacheDetailRespDto queryFrameInfoFrontCacheDetail(BffQueryFrameInfoFrontCacheDetailReqDto reqDto){
      
       
       GetSpaceInfoFromRedisRespDto getSpaceInfoFromRedisRes_1 = null;
PutSpaceInfoToRedisRespDto putSpaceInfoToRedisRespDto_1 = null;
//virtualUsage Redis获取空间信息  1586
      //ModelCode: getSpaceInfoFromRedis
        GetSpaceInfoFromRedisRespDto getSpaceInfoFromRedisRes = null;
    GetSpaceInfoFromRedisReqDto getSpaceInfoFromRedisReq=new GetSpaceInfoFromRedisReqDto();
  getSpaceInfoFromRedisReq.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:49466_1_1586
  
    /*Redis获取空间信息[1664]  入参：空间ID
出参：返回缓存中空间ID对应的数据 */
    
      getSpaceInfoFromRedisRes = nbCommon.getSpaceInfoFromRedis(getSpaceInfoFromRedisReq);
      
      getSpaceInfoFromRedisRes_1 = getSpaceInfoFromRedisRes;
if((getSpaceInfoFromRedisRes == null )) {
        //if(Redis获取空间信息.出参 等于空 )  1587
        
PutSpaceInfoToRedisRespDto putSpaceInfoToRedisRespDto = null;
    PutSpaceInfoToRedisReqDto putSpaceInfoToRedisReqDto=new PutSpaceInfoToRedisReqDto();
  putSpaceInfoToRedisReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:49492_1_1588
  
    /*空间信息存储缓存[1552]   */
    Assert.isNull(putSpaceInfoToRedisReqDto.getSpaceId(),"B查询空间框架信息前端缓存（公共）-空间信息存储缓存-空间ID不能为空",false);
      putSpaceInfoToRedisRespDto = fwBaseCommonClient.putSpaceInfoToRedis(putSpaceInfoToRedisReqDto).getData();
      
      putSpaceInfoToRedisRespDto_1 = putSpaceInfoToRedisRespDto;
//processBranchName:正常结束 ,processBranchId:1589
        
      }
BffQueryFrameInfoFrontCacheDetailRespDto retData = new BffQueryFrameInfoFrontCacheDetailRespDto();
  if(getSpaceInfoFromRedisRes_1!=null){
      retData.setSpaceId(getSpaceInfoFromRedisRes_1.getSpaceId());//sourceId:49523_1
retData.setSpaceCode(getSpaceInfoFromRedisRes_1.getSpaceCode());//sourceId:49524_1
retData.setSpaceName(getSpaceInfoFromRedisRes_1.getSpaceName());//sourceId:49525_1
retData.setSceneId(getSpaceInfoFromRedisRes_1.getSceneId());//sourceId:49526_1
retData.setSenceCode(getSpaceInfoFromRedisRes_1.getSenceCode());//sourceId:49527_1
retData.setSceneName(getSpaceInfoFromRedisRes_1.getSceneName());//sourceId:49528_1
retData.setAppId(getSpaceInfoFromRedisRes_1.getAppId());//sourceId:49529_1
retData.setAppCode(getSpaceInfoFromRedisRes_1.getAppCode());//sourceId:49530_1
retData.setAppName(getSpaceInfoFromRedisRes_1.getAppName());//sourceId:49531_1
retData.setAppIntroduce(getSpaceInfoFromRedisRes_1.getAppIntroduce());//sourceId:49532_1
retData.setAppUpdateIntroduct(getSpaceInfoFromRedisRes_1.getAppUpdateIntroduct());//sourceId:49533_1
retData.setWebsite(getSpaceInfoFromRedisRes_1.getWebsite());//sourceId:49534_1
retData.setAppLogo(getSpaceInfoFromRedisRes_1.getAppLogo());//sourceId:49535_1
retData.setAboutLogo(getSpaceInfoFromRedisRes_1.getAboutLogo());//sourceId:49536_1
retData.setAppBanner(getSpaceInfoFromRedisRes_1.getAppBanner());//sourceId:49537_1
retData.setServicePhone(getSpaceInfoFromRedisRes_1.getServicePhone());//sourceId:49538_1
retData.setServiceTime(getSpaceInfoFromRedisRes_1.getServiceTime());//sourceId:49539_1
retData.setCopyright(getSpaceInfoFromRedisRes_1.getCopyright());//sourceId:49540_1
retData.setAppVersion(getSpaceInfoFromRedisRes_1.getAppVersion());//sourceId:49541_1
retData.setIsEnableSms(getSpaceInfoFromRedisRes_1.getIsEnableSms());//sourceId:59728_1
retData.setIsUsePlatfomSms(getSpaceInfoFromRedisRes_1.getIsUsePlatfomSms());//sourceId:59729_1
retData.setAccessKeyId(getSpaceInfoFromRedisRes_1.getAccessKeyId());//sourceId:59730_1
retData.setAccessKeySecret(getSpaceInfoFromRedisRes_1.getAccessKeySecret());//sourceId:59731_1
retData.setIsOpenMultiOrg(getSpaceInfoFromRedisRes_1.getIsOpenMultiOrg());//sourceId:59732_1
retData.setOrgList(getSpaceInfoFromRedisRes_1.getOrgList().stream().map(item -> BeanUtil.toBean(item, BffOrgDto.class)).collect(Collectors.toList()));//sourceId:49547_1
    }
if(putSpaceInfoToRedisRespDto_1!=null){
      retData.setSpaceId(putSpaceInfoToRedisRespDto_1.getSpaceId());//sourceId:49523_1
retData.setSpaceCode(putSpaceInfoToRedisRespDto_1.getSpaceCode());//sourceId:49524_1
retData.setSpaceName(putSpaceInfoToRedisRespDto_1.getSpaceName());//sourceId:49525_1
retData.setSceneId(putSpaceInfoToRedisRespDto_1.getSceneId());//sourceId:49526_1
retData.setSenceCode(putSpaceInfoToRedisRespDto_1.getSenceCode());//sourceId:49527_1
retData.setSceneName(putSpaceInfoToRedisRespDto_1.getSceneName());//sourceId:49528_1
retData.setAppId(putSpaceInfoToRedisRespDto_1.getAppId());//sourceId:49529_1
retData.setAppCode(putSpaceInfoToRedisRespDto_1.getAppCode());//sourceId:49530_1
retData.setAppName(putSpaceInfoToRedisRespDto_1.getAppName());//sourceId:49531_1
retData.setAppIntroduce(putSpaceInfoToRedisRespDto_1.getAppIntroduce());//sourceId:49532_1
retData.setAppUpdateIntroduct(putSpaceInfoToRedisRespDto_1.getAppUpdateIntroduct());//sourceId:49533_1
retData.setWebsite(putSpaceInfoToRedisRespDto_1.getWebsite());//sourceId:49534_1
retData.setAppLogo(putSpaceInfoToRedisRespDto_1.getAppLogo());//sourceId:49535_1
retData.setAboutLogo(putSpaceInfoToRedisRespDto_1.getAboutLogo());//sourceId:49536_1
retData.setAppBanner(putSpaceInfoToRedisRespDto_1.getAppBanner());//sourceId:49537_1
retData.setServicePhone(putSpaceInfoToRedisRespDto_1.getServicePhone());//sourceId:49538_1
retData.setServiceTime(putSpaceInfoToRedisRespDto_1.getServiceTime());//sourceId:49539_1
retData.setCopyright(putSpaceInfoToRedisRespDto_1.getCopyright());//sourceId:49540_1
retData.setAppVersion(putSpaceInfoToRedisRespDto_1.getAppVersion());//sourceId:49541_1
retData.setIsEnableSms(putSpaceInfoToRedisRespDto_1.getIsOpenSmsService());//sourceId:59728_1
retData.setIsUsePlatfomSms(putSpaceInfoToRedisRespDto_1.getIsUsePlatformSmsService());//sourceId:59729_1
retData.setAccessKeyId(putSpaceInfoToRedisRespDto_1.getAccessKeyId());//sourceId:59730_1
retData.setAccessKeySecret(putSpaceInfoToRedisRespDto_1.getAccessKeySecret());//sourceId:59731_1
retData.setIsOpenMultiOrg(putSpaceInfoToRedisRespDto_1.getOpenManyOrg());//sourceId:59732_1
    }
  

  
  
return retData;
  }
    //

    /**
     * 图片上传
     *
     * @param use
     * @param file
     * @return
     * @throws Exception
     */
    @Override
    @BanAuto
    public String uploadImage(String storagePath, String use, String file,boolean useOss)
            throws Exception {
        if (file == null) {
            throw new BizException("上传文件不能为空", true);
        }

        if (!file.startsWith("", true);
        }

        final ImageEnums enums = ImageEnums.getEnumByCode(use);
        if (enums == null) {
            throw new BizException("非法的用途类型，use：" + use, true);
        }

        final String date = RandomUtils.getDateStr();
        final String uuid = RandomUtils.getUuid();
        String[] fileParts = file.split(",");
        final String type = fileParts[0].substring(fileParts[0].indexOf("/") + 1, fileParts[0].indexOf(";"));


        // 先存储源文件
        String complete = storagePath + File.separator + uuid + "." + type;
        String retStr = uuid + "." + type;

        // System.out.println("relativePath:"+relativePath);
        final File dirs = new File(storagePath);
        dirs.mkdirs();
        CommonFunctionHelper.GenerateImage(fileParts[1], complete,useOss);
        final File source = new File(complete);
        // 如果转换列表不为空 则按要求转换图片大小
        final List<ImageEnums.Size> sizes = enums.getSizes();

        if (CollUtil.isNotEmpty(sizes)) {
            for (ImageEnums.Size size : sizes) {
                final String target = storagePath + File.separator + uuid + size.getSuffix() + "." + type;
                this.convert(source, new File(target), size,useOss);
            }
        }

        return retStr;
    }

    public static void copyFile(File sourceFile, File destinationFile,boolean useOss) {
        try {
            if (useOss) {
                CommonFunctionHelper.uploadFileToAwazon("http://oss-cn-hangzhou.aliyuncs.com","cn-hangzhou","LTAI5tQBPJqiv8U2GRLwekX5","D1hXosHy8N2DlPGlAhu2YjVMe74FnM","xsz-public",null,destinationFile,destinationFile.getAbsolutePath());
            } else {
                // 复制到本地文件系统
                try (FileInputStream fis = new FileInputStream(sourceFile);
                     FileOutputStream fos = new FileOutputStream(destinationFile)) {

                    byte[] buffer = new byte[1024];
                    int bytesRead;
                    while ((bytesRead = fis.read(buffer)) != -1) {
                        fos.write(buffer, 0, bytesRead);
                    }
                    System.out.println("File copied to " + destinationFile.getAbsolutePath());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw new BizException("-1","copyFile未知异常"+ e,false);
        }
    }


    public void transFile(MultipartFile file,File source,boolean useOss){
        try {
            if (useOss) {
                CommonFunctionHelper.uploadFileToAwazon("http://oss-cn-hangzhou.aliyuncs.com","cn-hangzhou","LTAI5tQBPJqiv8U2GRLwekX5","D1hXosHy8N2DlPGlAhu2YjVMe74FnM","xsz-public",null,source,source.getAbsolutePath());

            } else{
                // 保存到本地文件系统
                file.transferTo(source);
                System.out.println("File saved to " + source.getAbsolutePath());
            }

        } catch (Exception e) {
            throw new BizException("-1","oss未知异常:"+ e,false);
        }

    }

    /**
     * 图片上传
     *
     * @param use
     * @param file
     * @return
     * @throws Exception
     */
    @Override
    @BanAuto
    @Trace(operationName = "上传文件")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
    public String uploadNoramlImage(String storagePath,String use, MultipartFile file,boolean useOss)
            throws Exception {
        if (file == null) {
            throw new BizException("上传文件不能为空", true);
        }


        final ImageEnums enums = ImageEnums.getEnumByCode(use);
        if (enums == null) {
            throw new BizException("非法的用途类型，use：" + use, true);
        }


        final String uuid = RandomUtils.getUuid();
        String fileName = file.getOriginalFilename();
        String type = "undefine";
        if(fileName.indexOf(".")>=0){
             type = fileName.substring(fileName.lastIndexOf(".") + 1);
        }

        Path path = Paths.get(storagePath);
        if (Files.notExists(path)) {
            Files.createDirectories(path);
        }


        // 先存储源文件
        String complete = storagePath  + uuid + "." + type;
        String retStr = uuid + "." + type;
        System.out.println(complete);
        System.out.println(storagePath);
        final File source = new File(complete);

        if(!source.exists()){
            source.createNewFile();
        }
        System.out.println(complete + " ： 文件创建成功");
        // 如果转换列表不为空 则按要求转换图片大小
        final List<ImageEnums.Size> sizes = enums.getSizes();

        if (CollUtil.isNotEmpty(sizes)) {
            transFile(file,source,useOss);
            for (ImageEnums.Size size : sizes) {
                final String target = storagePath  + uuid + size.getSuffix() + "." + type;

                if(enums.getCode().equals("OFFICICAL")
                 ||enums.getCode().equals("OFFICICAL_FILE")
                 ||enums.getCode().equals("WORK_PROJECT")
                 ||enums.getCode().equals("WORK_TASK")
                 ||enums.getCode().equals("WORK_QUESTION")
                 ||enums.getCode().equals("UPDATE_TASK_PROCESS")
                 ||enums.getCode().equals("UPDATE_PROJECT_PROCESS")
                 ||enums.getCode().equals("REPORT_THUMBNAIL")
                        ||enums.getCode().equals("WORK_TASK_THUMBNAIL_PIC")
                        ||enums.getCode().equals("PROBLEM_PIC")){
                    if(type.equals("jpeg")
                       ||type.equals("jpg")
                       ||type.equals("png")){
                        this.convertForEqual(source,new File(target),size.getWidth(),type,useOss);
                    }else{
                        final File targetFile = new File(target);
                        if(!targetFile.exists()){
                            targetFile.createNewFile();
                        }
                        copyFile(source,targetFile,useOss);
                    }

                }else{
                    this.convert(source, new File(target), size,useOss);
                }
            }
        }else{
            System.out.println(complete + " ： 文件开始复制");
            transFile(file,source,useOss);
            System.out.println(complete + " ： 文件复制成功");
        }

        return retStr;
    }

    /**
     * 创建文件路径
     *
     * @param paths
     * @return
     */
    private String createPath(String... paths) {
        String rootPath = "/www/server/";
        StringBuilder builder = new StringBuilder(rootPath);
        for (String path : paths) {
            builder.append(File.separator).append(path);
        }
        final String path = builder.toString();
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        return path;
    }

    /**
     * 获得相对文件路径
     *
     * @param paths
     * @return
     */
    private String createRelativePath(String... paths) {

        String rootPath = "/www/server/";
        StringBuilder builder = new StringBuilder("");
        for (String path : paths) {
            builder.append(File.separator).append(path);
        }
        String path = builder.toString();
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        if (path.indexOf("/") == 0) {
            path = path.substring(1);
        }
        return path;
    }

    /**
     * 图片尺寸转换
     *
     * @param source
     * @param target
     * @param size
     */
    private void convert(File source, File target, ImageEnums.Size size,boolean useOss) {
        if(useOss){
            InputStream in = null;
            try {
                in = new FileInputStream(source);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }


            try {
                // 首先将图片转换为指定大小
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                Thumbnails.of(in).size(size.getWidth(), size.getHigh()).toOutputStream(baos);
                byte[] bytes = baos.toByteArray();

                CommonFunctionHelper.uploadFileToAwazon("http://oss-cn-hangzhou.aliyuncs.com","cn-hangzhou","LTAI5tQBPJqiv8U2GRLwekX5","D1hXosHy8N2DlPGlAhu2YjVMe74FnM","xsz-public",bytes,null,target.getAbsolutePath());
            } catch (Exception e) {
                System.out.println("Error occurred while creating MinioClient: " + e.getMessage());
            }


        }else{

        }
        try (InputStream in = new FileInputStream(source);
             OutputStream out = new FileOutputStream(target)) {
            Thumbnails.of(in).size(size.getWidth(), size.getHigh()).toOutputStream(out);
        } catch (Exception e) {
            throw new BizException("file convert size filed, size" + size, true);
        }
    }

    private void convertForEqual(File source, File target,  int size,String type,boolean useOss) {
        try {
            // 加载原始图片
            BufferedImage originalImage = ImageIO.read(source);

            // 计算新尺寸
            int originalWidth = originalImage.getWidth();
            int originalHeight = originalImage.getHeight();
            int newWidth = size;
            int newHeight = (newWidth * originalHeight) / originalWidth;

            // 创建新的缩放后图片
            BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2d = resizedImage.createGraphics();

            // 绘制调整大小后的图片
            g2d.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
            g2d.dispose();




            if (useOss) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageIO.write(resizedImage, type, baos);
                byte[] bytes = baos.toByteArray();
                CommonFunctionHelper.uploadFileToAwazon("http://oss-cn-hangzhou.aliyuncs.com","cn-hangzhou","LTAI5tQBPJqiv8U2GRLwekX5","D1hXosHy8N2DlPGlAhu2YjVMe74FnM","xsz-public",bytes,null,target.getAbsolutePath());
            } else {
                // 保存到本地文件系统
                ImageIO.write(resizedImage, type, target);
                System.out.println("File resized and saved to " + target.getAbsolutePath());
            }


        } catch (IOException e) {
            throw new BizException("-1","convertForEqual 未知异常:"+ e,false);
        }
    }

    /**
   * B存档批次下单条数据（公共）[1411]
   * gen by moon at 8/10/2022, 3:35:21 AM
   */
    @Trace(operationName = "B存档批次下单条数据（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffArchiveBatchSingleDataComRespDto archiveBatchSingleDataCom(BffArchiveBatchSingleDataComReqDto reqDto){
      
       
       //步骤0: D1-存档批次下单条数据 - archiveBatchSingleData
     ArchiveBatchSingleDataRespDto archiveBatchSingleDataRespDto = null;
    ArchiveBatchSingleDataReqDto archiveBatchSingleDataReqDto=new ArchiveBatchSingleDataReqDto();
  if(reqDto!=null){
      archiveBatchSingleDataReqDto.setObjectCode(reqDto.getObjectCode());//sourceId:68271_1
archiveBatchSingleDataReqDto.setPropertyCode(reqDto.getPropertyCode());//sourceId:68272_1
archiveBatchSingleDataReqDto.setUniqueId(reqDto.getUniqueId());//sourceId:68273_1
    }
  
    /*D1-存档批次下单条数据[2327]   */
    
      archiveBatchSingleDataRespDto = fwBaseCommonClient.archiveBatchSingleData(archiveBatchSingleDataReqDto).getData();
      
      
    
BffArchiveBatchSingleDataComRespDto retData = new BffArchiveBatchSingleDataComRespDto();
  
  

  
  
return retData;
  }

    /**
   * B修改排序（公共）[1285]
   * gen by moon at 8/10/2022, 3:33:57 AM
   */
    @Trace(operationName = "B修改排序（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffUpdateSortNumComRespDto updateSortNumCom(BffUpdateSortNumComReqDto reqDto){
      
       
       //步骤0: D1-修改排序 - updateSortNum
     UpdateSortNumRespDto updateSortNumRespDto = null;
    UpdateSortNumReqDto updateSortNumReqDto=new UpdateSortNumReqDto();
  if(reqDto!=null){
      updateSortNumReqDto.setObjectCode(reqDto.getObjectCode());//sourceId:42876_1
updateSortNumReqDto.setPropertyCode(reqDto.getPropertyCode());//sourceId:42877_1
updateSortNumReqDto.setUniqueId(reqDto.getUniqueId());//sourceId:42878_1
updateSortNumReqDto.setNumber(reqDto.getNumber());//sourceId:42879_1
    }
  
    /*D1-修改排序[1530]   */
    Assert.isNull(updateSortNumReqDto.getObjectCode(),"B修改排序（公共）-D1-修改排序-业务对象编码不能为空",false);
Assert.isNull(updateSortNumReqDto.getPropertyCode(),"B修改排序（公共）-D1-修改排序-对象属性编码不能为空",false);
Assert.isNull(updateSortNumReqDto.getUniqueId(),"B修改排序（公共）-D1-修改排序-主键ID不能为空",false);
Assert.isNull(updateSortNumReqDto.getNumber(),"B修改排序（公共）-D1-修改排序-排序数字不能为空",false);
      updateSortNumRespDto = fwBaseCommonClient.updateSortNum(updateSortNumReqDto).getData();
      
      
    
BffUpdateSortNumComRespDto retData = new BffUpdateSortNumComRespDto();
  
  

  
  
return retData;
  }

    /**
   * B发布单条数据（公共）[607]
   * gen by moon at 8/10/2022, 3:29:39 AM
   */
    @Trace(operationName = "B发布单条数据（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffReleaseSingleDataComRespDto releaseSingleDataCom(BffReleaseSingleDataComReqDto reqDto){
      
       
       //步骤0: D1-发布单条数据 - releaseSingleData
     ReleaseSingleDataRespDto releaseSingleDataRespDto = null;
    ReleaseSingleDataReqDto releaseSingleDataReqDto=new ReleaseSingleDataReqDto();
  if(reqDto!=null){
      releaseSingleDataReqDto.setObjectCode(reqDto.getObjectCode());//sourceId:68283_1
releaseSingleDataReqDto.setPropertyCode(reqDto.getPropertyCode());//sourceId:68284_1
releaseSingleDataReqDto.setUniqueId(reqDto.getUniqueId());//sourceId:68285_1
    }
  
    /*D1-发布单条数据[2329]   */
    Assert.isNull(releaseSingleDataReqDto.getObjectCode(),"B发布单条数据（公共）-D1-发布单条数据-业务对象编码不能为空",false);
Assert.isNull(releaseSingleDataReqDto.getPropertyCode(),"B发布单条数据（公共）-D1-发布单条数据-对象属性编码不能为空",false);
Assert.isNull(releaseSingleDataReqDto.getUniqueId(),"B发布单条数据（公共）-D1-发布单条数据-主键ID不能为空",false);
      releaseSingleDataRespDto = fwBaseCommonClient.releaseSingleData(releaseSingleDataReqDto).getData();
      
      
    
BffReleaseSingleDataComRespDto retData = new BffReleaseSingleDataComRespDto();
  
  

  
  
return retData;
  }

    /**
   * B撤销存档批次下单条数据（公共）[606]
   * gen by moon at 8/10/2022, 3:29:35 AM
   */
    @Trace(operationName = "B撤销存档批次下单条数据（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffUndoArchiveBatchSingleDataComRespDto undoArchiveBatchSingleDataCom(BffUndoArchiveBatchSingleDataComReqDto reqDto){
      
       
       //步骤0: D1-撤销存档批次下单条数据 - undoArchiveBatchSingleData
     UndoArchiveBatchSingleDataRespDto undoArchiveBatchSingleDataRespDto = null;
    UndoArchiveBatchSingleDataReqDto undoArchiveBatchSingleDataReqDto=new UndoArchiveBatchSingleDataReqDto();
  if(reqDto!=null){
      undoArchiveBatchSingleDataReqDto.setObjectCode(reqDto.getObjectCode());//sourceId:68277_1
undoArchiveBatchSingleDataReqDto.setPropertyCode(reqDto.getPropertyCode());//sourceId:68278_1
undoArchiveBatchSingleDataReqDto.setUniqueId(reqDto.getUniqueId());//sourceId:68279_1
    }
  
    /*D1-撤销存档批次下单条数据[2328]   */
    
      undoArchiveBatchSingleDataRespDto = fwBaseCommonClient.undoArchiveBatchSingleData(undoArchiveBatchSingleDataReqDto).getData();
      
      
    
BffUndoArchiveBatchSingleDataComRespDto retData = new BffUndoArchiveBatchSingleDataComRespDto();
  
  

  
  
return retData;
  }

    /**
   * B批量修改排序（公共）[1807]
   * gen by moon at 8/10/2022, 3:37:54 AM
   */
    @Trace(operationName = "B批量修改排序（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffBatchUpdateSortNumRespDto batchUpdateSortNum(BffBatchUpdateSortNumReqDto reqDto){
      
       
       //步骤0: D-批量改排序 - batchUpdateSortNum
     BatchUpdateSortNumRespDto batchUpdateSortNumRespDto = null;
    BatchUpdateSortNumReqDto batchUpdateSortNumReqDto=new BatchUpdateSortNumReqDto();
  if(reqDto!=null){
      for (BffObjAttributeIdDto item : reqDto.getObjAttributeIdList()) {
                ObjAttributeIdDto oneItem = new ObjAttributeIdDto();
                if(reqDto!=null){
      oneItem.setPropertyCode(reqDto.getPropertyCode());//sourceId:30091_2
oneItem.setUniqueId(item.getUniqueId());//sourceId:30092_2
oneItem.setNumber(item.getNumber());//sourceId:30093_2
oneItem.setObjectCode(reqDto.getObjectCode());//sourceId:49304_2
    }
               
                batchUpdateSortNumReqDto.getObjAttributeIdList().add(oneItem);
            }//sourceId:55249_1
    }
  
    /*D-批量改排序[1808]   */
    
      batchUpdateSortNumRespDto = fwBaseCommonClient.batchUpdateSortNum(batchUpdateSortNumReqDto).getData();
      
      
    
BffBatchUpdateSortNumRespDto retData = new BffBatchUpdateSortNumRespDto();
  
  

  
  
return retData;
  }

    /**
   * B删除单条数据（公共）[1410]
   * gen by moon at 8/10/2022, 3:35:19 AM
   */
    @Trace(operationName = "B删除单条数据（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffDeleteSingleDataComRespDto deleteSingleDataCom(BffDeleteSingleDataComReqDto reqDto){
      
       
       //步骤0: D1-删除单条数据 - deleteSingleData
     DeleteSingleDataRespDto deleteSingleDataRespDto = null;
    DeleteSingleDataReqDto deleteSingleDataReqDto=new DeleteSingleDataReqDto();
  if(reqDto!=null){
      deleteSingleDataReqDto.setObjectCode(reqDto.getObjectCode());//sourceId:68289_1
deleteSingleDataReqDto.setPropertyCode(reqDto.getPropertyCode());//sourceId:68290_1
deleteSingleDataReqDto.setUniqueId(reqDto.getUniqueId());//sourceId:68291_1
    }
  
    /*D1-删除单条数据[2330]   */
    Assert.isNull(deleteSingleDataReqDto.getObjectCode(),"B删除单条数据（公共）-D1-删除单条数据-业务对象编码不能为空",false);
Assert.isNull(deleteSingleDataReqDto.getPropertyCode(),"B删除单条数据（公共）-D1-删除单条数据-对象属性编码不能为空",false);
Assert.isNull(deleteSingleDataReqDto.getUniqueId(),"B删除单条数据（公共）-D1-删除单条数据-主键ID不能为空",false);
      deleteSingleDataRespDto = fwBaseCommonClient.deleteSingleData(deleteSingleDataReqDto).getData();
      
      
    
BffDeleteSingleDataComRespDto retData = new BffDeleteSingleDataComRespDto();
  
  

  
  
return retData;
  }

    /**
   * B存档单条数据（公共）[370]
   * gen by moon at 8/10/2022, 3:29:12 AM
   */
    @Trace(operationName = "B存档单条数据（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffArchiveSingleDataComRespDto archiveSingleDataCom(BffArchiveSingleDataComReqDto reqDto){
      
       
       //步骤0: D1-存档单条数据 - archiveSingleData
     ArchiveSingleDataRespDto archiveSingleDataRespDto = null;
    ArchiveSingleDataReqDto archiveSingleDataReqDto=new ArchiveSingleDataReqDto();
  if(reqDto!=null){
      archiveSingleDataReqDto.setObjectCode(reqDto.getObjectCode());//sourceId:68265_1
archiveSingleDataReqDto.setPropertyCode(reqDto.getPropertyCode());//sourceId:68266_1
archiveSingleDataReqDto.setUniqueId(reqDto.getUniqueId());//sourceId:68267_1
    }
  
    /*D1-存档单条数据[2326]   */
    Assert.isNull(archiveSingleDataReqDto.getObjectCode(),"B存档单条数据（公共）-D1-存档单条数据-业务对象编码不能为空",false);
Assert.isNull(archiveSingleDataReqDto.getPropertyCode(),"B存档单条数据（公共）-D1-存档单条数据-对象属性编码不能为空",false);
Assert.isNull(archiveSingleDataReqDto.getUniqueId(),"B存档单条数据（公共）-D1-存档单条数据-主键ID不能为空",false);
      archiveSingleDataRespDto = fwBaseCommonClient.archiveSingleData(archiveSingleDataReqDto).getData();
      
      
    
BffArchiveSingleDataComRespDto retData = new BffArchiveSingleDataComRespDto();
  
  

  
  
return retData;
  }

    /**
   * B查询城市列表[1122]
   * gen by moon at 8/10/2022, 3:33:04 AM
   */
    @Trace(operationName = "B查询城市列表")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffQueryQueryCityListListRespDto queryQueryCityListList(BffQueryQueryCityListListReqDto reqDto){
      
       
       BffQueryQueryCityListListRespDto retData = new BffQueryQueryCityListListRespDto();
  
  

      List<Object> allNodes =new ArrayList<>();
      
     List<TreeNode> nodeList = CommonFunctionHelper.buildTree(allNodes);
     retData.setTreeNode(nodeList);
     
    
return retData;
  }

    /**
   * B上传附件（公共）[741]
   * gen by moon at 8/10/2022, 3:30:19 AM
   */
    @Trace(operationName = "B上传附件（公共）")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffAddUploadFileRespDto addUploadFile(BffAddUploadFileReqDto reqDto){
      
       
       AddUploadFileRespDto addUploadFileRespDto_1 = null;
//步骤0: D上传附件 - addUploadFile
     AddUploadFileRespDto addUploadFileRespDto = null;
    AddUploadFileReqDto addUploadFileReqDto=new AddUploadFileReqDto();
  if(reqDto!=null){
      addUploadFileReqDto.setUse(reqDto.getUse());//sourceId:64184_1
addUploadFileReqDto.setFile(reqDto.getFile());//sourceId:64186_1
addUploadFileReqDto.setScope(reqDto.getScope());//sourceId:64232_1
addUploadFileReqDto.setSpaceId(reqDto.getSpaceId());//sourceId:64233_1
    }
  
    /*D上传附件[1836]   */
    Assert.isNull(addUploadFileReqDto.getUse(),"B上传附件（公共）-D上传附件-用途不能为空",false);
Assert.isNull(addUploadFileReqDto.getFile(),"B上传附件（公共）-D上传附件-上传文件不能为空",false);
      addUploadFileRespDto = fwBaseCommonClient.addUploadFile(addUploadFileReqDto).getData();
      
      addUploadFileRespDto_1 = addUploadFileRespDto;
    
BffAddUploadFileRespDto retData = new BffAddUploadFileRespDto();
  if(addUploadFileRespDto_1!=null){
      retData.setUrl(addUploadFileRespDto_1.getUrl());//sourceId:56479_1
    }
  

  
  
return retData;
  }

    /**
   * B1-2上传组织架构模板[1030]
   * gen by moon at 8/10/2022, 3:31:47 AM
   */
    @Trace(operationName = "B1-2上传组织架构模板")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffAddUploadOrgTemplateRespDto addUploadOrgTemplate(BffAddUploadOrgTemplateReqDto reqDto){
      
       
       BffAddUploadOrgTemplateRespDto retData = new BffAddUploadOrgTemplateRespDto();
  
  

  
  
return retData;
  }
}
